//
// TileBox.cs
//
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
//

using System;
using System.Text;
using System.Reflection;
using System.Collections.Generic;

using Gtk;

using Dashboard;
using Dashboard.Util;
using Dashboard.Mint.Theatrics;

namespace Dashboard.Mint.Tiles
{
	public class TileBox : Gtk.Button, IComparable<Tile>
	{
		private const int DEFAULT_ICON_SIZE = 24;

		private Tile tile = null;

		private Image image = null;
		private Label title = null;
		private Label description = null;

		public TileBox (Tile tile)
		{
			if (tile == null)
				throw new ArgumentException ("Tile is null");

			this.tile = tile;

			HBox hbox = new HBox (false, 5);
			hbox.BorderWidth = 2;

			image = new Image ();
			image.Pixbuf = tile.GetIcon (DEFAULT_ICON_SIZE);
			hbox.PackStart (image, false, true, 0);

			VBox vbox = new VBox (false, 2);
			hbox.PackStart (vbox, true, true, 0);

			title = new Label();
			title.Markup = "<b>" + GLib.Markup.EscapeText (tile.Title) + "</b>";
			title.Ellipsize = Pango.EllipsizeMode.End;
			title.Xalign = 0.0f;
			vbox.PackStart (title, false, true, 0);

			description = new Label ();
			description.Text = tile.Description;
			description.Ellipsize = Pango.EllipsizeMode.End;
			description.Xalign = 0.0f;
			vbox.PackStart (description, false, true, 0);

			hbox.ShowAll ();
			
			Add (hbox);
		}

		public int CompareTo (Tile other)
		{
			return other.CompareTo (tile);
		}

		public Tile Tile
		{
			get { return tile; }
		}

		public Gdk.Pixbuf Icon {
			get { return image.Pixbuf; }
			set { image.Pixbuf = value; } // .ScaleSimple (16, 16, Gdk.InterpType.Bilinear);
		}
	}
}
